package com.ymatou.app.api.service;

import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;

/**
 * 根据主题Id和模板名称，获取模板Call FreeMaker Template自动生成代码
 */
public class TopicTemplateCall extends YmatouBaseCall {
	private static String opurl = "api/Group/TopicTemplate";

	public TopicTemplateCall() {
		super(EnvSetup.getSystemUrl("api_app"), opurl, "POST", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	}

	/**
	 * 获取code
	 */
	public String getCode() {
		String Code = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Code = jo.getString("Code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 */
	public String getBCode() {
		String BCode = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			BCode = jo.getString("BCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return Data
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Data = jo.getJSONObject("Data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	/**
	 * 获取Status
	 */
	public boolean getStatus() {
		boolean res = false;
		try {
			res = (Boolean) getData().get("Status");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}

	/**
	 * 获取Message
	 */
	public String getMessage() {
		String res = null;
		try {
			res = getData().getString("Message");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}

	/**
	 * 获取Msg
	 */
	public String getMsg() {
		String Msg = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Msg = jo.getString("Msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Msg;
	}

	/**
	 * 获取TuanTemplate
	 */
	public JSONObject getTuanTemplate() {
		JSONObject TuanTemplate = null;
		try {
			TuanTemplate = getData().getJSONObject("TuanTemplate");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return TuanTemplate;
	}

	/**
	 * 获取TopicId
	 */
	public Integer getTopicId() {
		Integer TopicId = 0;
		try {
			TopicId = getTuanTemplate().getInt("TopicId");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return TopicId;
	}

	/**
	 * 获取TemplateName
	 */
	public String getTemplateName() {
		String TemplateName = null;
		try {
			TemplateName = getTuanTemplate().getString("TemplateName");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return TemplateName;
	}

	/**
	 * 获取Sequence
	 */
	public Integer getSequence() {
		Integer Sequence = 0;
		try {
			Sequence = getTuanTemplate().getInt("Sequence");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Sequence;
	}

	/**
	 * 获取TemplateHtml
	 */
	public String getTemplateHtml() {
		String TemplateHtml = null;
		try {
			TemplateHtml = getTuanTemplate().getString("TemplateHtml");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return TemplateHtml;
	}
}